<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" href="../../css/fontawesome/css/all.min.css">
    <script src="../../css/fontawesome/js/all.min.js"></script>
</head>

<body>
    <h2>添加用户</h2>

    <div class="mx-5">
        <form name="form">
            <div class="mb-3">
                <label class="form-label">用户名</label>
                <input type="text" name="username" class="form-control">
            </div>
            <div class="mb-3">
                <label class="form-label">姓名</label>
                <input type="text" name="name" class="form-control">
            </div>
            <div class="mb-3">
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" checked name="gender" value="1">
                    <label class="form-check-label">
                        男
                    </label>
                </div>
                <div class="form-check form-check-inline">
                    <input class="form-check-input" type="radio" name="gender" value="2">
                    <label class="form-check-label">
                        女
                    </label>
                </div>
            </div>
            <div class="mb-3">
                <label class="form-label">年龄</label>
                <input type="number" name="age" class="form-control">
            </div>
            <div class="mb-3">
                <label class="form-label">邮箱</label>
                <input type="text" name="email" class="form-control">
            </div>
            <div class="mb-3">
                <div class="form-check">
                    <input class="form-check-input" type="checkbox" name="emailVisibility">
                    <label class="form-check-label">
                        是否显示邮箱
                    </label>
                </div>
            </div>

            <div class="mb-3">
                <label class="form-label">手机</label>
                <input type="text" name="phone" class="form-control">
            </div>

            <div class="mb-3">
                <label class="form-label">密码</label>
                <input type="text" name="password" class="form-control">
            </div>

            <div class="mb-3">
                <label class="form-label">确认密码</label>
                <input type="text" name="passwordConfirm" class="form-control">
            </div>
            <div class="mb-3">
                <button type="button" data-action="save" class="btn btn-primary">保存</button>
            </div>
        </form>
    </div>

    <script type="module">
        import PocketBase from '../../js/pocketbase.es.js';
        import _on from '../../js/_on.js';
        import _confirm from '../../js/_confirm.js';
        import _reUrl from '../../js/_reUrl.js';
        const html = String.raw;
        const pb = new PocketBase('http://127.0.0.1:8090');

        _reUrl();








        const form = document.form;
        _on('click', {
            async save() {
                try {
                    await pb.collection('users').create({
                        "username": form.username.value,
                        "email": form.email.value,
                        "emailVisibility": form.emailVisibility.checked,
                        "password": form.password.value,
                        "passwordConfirm": form.passwordConfirm.value,
                        "name": form.name.value,
                        "phone": form.phone.value,
                        "gender": form.gender.value,
                        "age": form.age.value
                    });
                    location.href = "./users.html"
                } catch (error) {
                    console.log(error);
                }


            }
        })

    </script>
</body>

</html>